home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OOPTUT34.ZIP / VIEWS.TXT < prev    next >
Text File  |  1993-06-12  |  9KB  |  202 lines

  1.  
  2.                              VIEWS. 
  3.                              ------ 
  4.  
  5.  The basic building block of a Turbo Vision application is the view, which
  6.  is an object that manages a rectangular area of the screen.  The menu bar
  7.  at the top of the screen is a view and any program action in that area of
  8.  the screen (e.g. a mouse click) will be dealt with by the view that
  9.  controls that area.
  10.  
  11.  Menus, windows, the status line, buttons, scroll bars, dialog boxes are all
  12.  views.  The program itself is a view as it controls the entire area of the
  13.  screen, although it sets up other views, called subviews, to handle the
  14.  interaction with the user.
  15.  
  16.  Tview, the immediate descendant of TObject, provides the start for Turbo
  17.  Vision and contains the basic screen management methods and fields.  It is
  18.  able to draw itself at any time, using the virtual method called 'draw' and
  19.  it is able to handle events that are directed to it.
  20.  
  21.  The location of a view is determined by two points of type TPoint, which
  22.  contain two fields, the X and Y coordinates of the points.  The first
  23.  point, the 'Origin', is the top left corner of the new view, measured
  24.  relative to the coordinate system of the owner view.  The second point, the
  25.  'Size', is the bottom right corner of the new view measured relative to its
  26.  own origin.  Both points are contained in an object of type TRect.
  27.  
  28.  TRect and TView both provide useful methods for manipulating the size of a
  29.  view.  The example below illustrates how to create a view that just fits
  30.  inside a window.
  31.  
  32.       PROCEDURE ThisWindow.MakeInside;
  33.       VAR
  34.         R: TRect;
  35.         Inside: PInsideView;
  36.       BEGIN
  37.       GetExtent(R);                          {sets R to size of ThisWindow}
  38.         R.Grow(-1, -1);                 {shrinks rectangle by 1, both ways}
  39.         Inside := New(PInsideView, Init(R));          {creates inside view}
  40.         Insert(Inside);                      {inserts new view into window}
  41.       END;
  42.  
  43.  GetExtent is a TView method that sets the argument, TRect, to the
  44.  coordinates of a rectangle covering the entire view.  Grow is a TRect
  45.  method that increases the horizontal and vertical sizes of a rectangle.
  46.  
  47.  It is essential that a view must cover the entire area for which it is
  48.  responsible.  Failure to fill the whole area and the resultant uncertainty
  49.  is illustrated by the example program TVGUID05.PAS.  A view must also be
  50.  able to draw itself at any time, particularly after it has been covered or
  51.  moved or changed.
  52.  
  53.  Views frequently contain the initiator of an 'event', such as the status
  54.  line invitation 'Close', which is dealt with by a virtual method called
  55.  'HandleEvent', available in the hierarchy from TView to TGroup to TProgram,
  56.  but generally overridden for a specific application.
  57.  
  58.  TGroup and its descendants are collectively referred to as 'groups',
  59.  whereas other views are called 'terminal' views.  A group is just an empty
  60.  box that contains and manages 'subviews'.  An example is TApplication,
  61.  which controls the whole screen, but owns three subviews; the menu bar, the
  62.  desktop and the status line.
  63.  
  64.  Subviews are created and then inserted into groups by the TGroup 'insert'
  65.  procedure, as shown on page 87 of the Guide and below:
  66.  
  67.       InitDeskTop;
  68.       ...
  69.       ...
  70.       IF DeskTop <> NIL THEN Insert(DeskTop);
  71.       ...
  72.       ...
  73.  
  74.  It is possible to have multiple, overlapping windows on the desktop, as
  75.  groups know how to handle overlapping subviews.
  76.  
  77.  Groups keep track of the order in which subviews are inserted.  Several
  78.  two-dimensional (X,Y) views can be considered to be in the form of layers
  79.  in the third dimension (Z) and so the order is called the 'Z-order'.  The
  80.  last view inserted is the 'front' view.
  81.  
  82.  Groups do not draw themselves directly, but call on each of the subviews to
  83.  draw themselves, in Z-order, so that the most recently inserted subview
  84.  will be in front of the others.
  85.  
  86.  Views are related to each other in two ways: they are members of the Turbo
  87.  Vision hierarchy and they are members of a 'view tree'.  These two distinct
  88.  relationships are differentiated by the diagrams below:
  89.  
  90.  TObject -- TView -----
  91.                     |-- TButton
  92.                     |--
  93.                     |-- TFrame
  94.                     |-- TGroup -----
  95.                     |            |--
  96.                     |            |--TWindow -----TDialog
  97.                     |
  98.                     |
  99.                     |
  100.                     |-- TStaticText -----
  101.                     |
  102.  
  103.  The hierarchy, shown above, indicates that TButton, TFrame, TDialog and
  104.  TStaticText are all descendants of Tview.  However a TDialog view owns a
  105.  TButton, TFrame and a TStaticText, so a view tree can be constructed, as
  106.  below:
  107.  
  108.                           TDialog
  109.                           |  |  |
  110.            ----------------  |  ------------------
  111.            |                 |                   |
  112.          TFrame           TButton            TStaticText
  113.  
  114.  
  115.  Here TDialog is not an ancestor of TButton, but it owns TButton. The links
  116.  indicate ownership, not inheritance.
  117.  
  118.  Figures 4.11 and 4.12 of the Turbo Vision Guide illustrate another view
  119.  tree situation for an application which shows two overlapping file viewer
  120.  windows in the desktop. The view tree is as shown here:
  121.  
  122.                             Application
  123.                              |   |   |
  124.              ----------------    |    ------------------
  125.              |                   |                     |
  126.          MenuBar              DeskTop              StatusLine
  127.                                |   |
  128.               -----------------     -------------------
  129.               |                                       |
  130.            Window                                  Window
  131.            | | | |                                 | | | |
  132.     -------  | |  -------                  --------  | |  ---------
  133.     |        | |        |                  |         | |          |
  134.   Frame      | |     Scroller            Frame       | |       Scroller
  135.              | |                                     | |
  136.      --------   --------                     --------   --------
  137.      |                 |                     |                 |
  138.   Scroll Bar       Scroll Bar            Scroll Bar        Scroll Bar
  139.  
  140.                                 
  141.            
  142.  Selected and focused views.
  143.  ---------------------------
  144.  
  145.  Within each group of views, one and only one subview is selected.  With
  146.  menu bar, desktop and status line, it is desktop that is selected, because
  147.  that is where further work will take place.
  148.  
  149.  When several windows are open on the desktop, the selected window is the
  150.  one the user is currently working, called the 'active' window (usually the
  151.  topmost).
  152.  
  153.  Within the active window, the selected subview is called the focused view.
  154.  For example, in a dialog box, the focused view is the highlighted control.
  155.  
  156.  In the application view tree shown above, Application is the 'modal view'
  157.  and DeskTop is its selected view.  Within desktop, the second (more
  158.  recently inserted) window is selected and therefore active.  Within that
  159.  window, the scrolling interior is selected and, because it is a terminal
  160.  view, it is the end of the chain, the focused view.
  161.  
  162.  The currently focused view is usually highlighted on the screen.  For
  163.  example, in a dialog box, the focused control view is brighter than the
  164.  others, indicating that it will be acted upon if the user presses 'Enter'.
  165.  
  166.  When a group of views is created, the owner view specifies which of its
  167.  subviews is to be focused by calling that subview's 'Select' method.  This
  168.  establishes the default focus.
  169.  
  170.  The user may however change the view that has the focus by clicking the
  171.  mouse on a different subview.  In a dialog box, pressing the tab key also
  172.  moves the focus, as does the pressing of an appropriate hot key.
  173.  
  174.  Some views are not selectable, including the background of the desktop,
  175.  frames of windows and scroll bars.  User created views can be designated
  176.  selectable or otherwise.
  177.  
  178.  The chain of views from the parent object to the focused view is called the
  179.  'focus chain'.
  180.  
  181.  
  182.  Modal views.
  183.  ------------
  184.  
  185.  A view may define a mode of operation, or of acting or functioning, in
  186.  which case it is called the 'modal view'.  In the integrated development
  187.  environment the modes are editing, debugging, compiling and run. Depending
  188.  on which of these modes is active, keys on the keyboard may have varying
  189.  effects.  Dialog boxes are usually modal and, when active, nothing outside
  190.  it functions.
  191.  
  192.  When a user instantiates a view and makes it modal, only that view and its
  193.  subviews can interact with that user.  Events are handled only by the modal
  194.  view and its subviews.  Any part of the view tree that is not the modal
  195.  view or owned by the modal view is inactive.
  196.  
  197.  
  198.  VIEWS.WR1
  199.  VIEWS.TXT
  200.  3.4.91
  201.  
  202.